﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace ACCPS1ProjectDemo.ControlDemo
{
    public partial class ChartDemo : UserControl
    {
        public ChartDemo()
        {
            InitializeComponent();
        }
        DBHelper helper = new DBHelper();

        private DataTable GetData()
        {
            string sql = "select SubjectName,avg(studentResult) as AvgScore from Result as r inner join Subject as s on r.subjectId=s.subjectId group by subjectName";
            return helper.ExectueTable(sql);
        }
        
        private void ChartDemo_Load(object sender, EventArgs e)
        {
            DataTable dt = GetData();
            //DataGridView控件显示数据
            dataGridView1.DataSource = dt;
            //Chart显示图表
            chart1.Series[0].Label = "分";
            chart1.Series[0].XValueMember = "SubjectName";
            chart1.Series[0].YValueMembers = "AvgScore";
            chart1.DataSource = dt;
        }
    }
}
